package com.jun.seckill_by_jun.dao;

import com.jun.seckill_by_jun.domain.OrderInfo;
import com.jun.seckill_by_jun.domain.SeckillOrder;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface OrderDao {
    @Select("SELECT * FROM sk_order WHERE user_id = #{id} AND goods_id = #{gid}")
    public SeckillOrder getOrderByUserIdGoodsId(@Param("id") long id,@Param("gid") long goodsId);

    @Insert("insert into sk_order_info(user_id, goods_id, goods_name, goods_count, goods_price, order_channel, status, create_date)values("
            + "#{userId}, #{goodsId}, #{goodsName}, #{goodsCount}, #{goodsPrice}, #{orderChannel},#{status},#{createDate} )")
    @SelectKey(keyColumn = "id", keyProperty = "id", resultType = long.class, before = false, statement = "select last_insert_id()")
    public long insert(OrderInfo orderInfo);

    @Insert("insert into sk_order (user_id, goods_id, order_id)values(#{userId}, #{goodsId}, #{orderId})")
    void insertSeckillOrder(SeckillOrder seckillOrder);

    @Select("select * from sk_order_info where id = #{orderId}")
    OrderInfo getOrderByOrderId(@Param("orderId") long orderId);
}
